<%--
	author:chengd
	time:2012/5/12 18:06:10
--%>



<%@page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib uri="TowkerTagLib" prefix="rbac"%>
<%@ taglib uri="/WEB-INF/tags/CommonFunction.tld" prefix="cfn" %>
<%@include file="/commons/include/html_doctype.html"%>
<html>
<head>
	<title>修改</title>
	<%@include file="/commons/include/upd.jsp" %>
    <script type="text/javascript" src="${ctx}/js/calendar/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript">
$(function(){
	
	jQuery("#dataForm").validate(
	{
		rules: {
		},
		messages: {
		},
		submitHandler:function(form)
		{
			setGoodsInfo();
			jQuery(form).ajaxSubmit(_options);
		}
	});
});
_callback = function() {
	location.href = ctx + "/manage/sell/getSellPlanApp.htm";
}
validCallBack = function()
{
	if($("#goodsInfo").val() == "") {
		alert("请选择产品!");
		return false;
	}
	return true;
};
function setGoodsInfo() {
	var goodsInfoStr = "";
	//添加页面自定义校验
	for(var id in goods) {
		goodsInfoStr += id + ",";
	}
	//alert(goodsInfoStr);
	$("#goodsInfo").attr("value", goodsInfoStr);
}
var goods = {};
//JavaScript Document
function selectGoods() {
	//showModelessDialog
	//encodeURI、encodeURIComponent
	var source = encodeURIComponent(ctx+"/manage/basicData/selectGoods.htm?typeid=&classId=&r=" + Math.random());
	var url = ctx + "/commons/showDialog.jsp?r=" + Math.random() + "&url=" + source;
	var result = window.showModalDialog(url, this, "dialogWidth=600px;dialogHeight=600px;scroll=no");
	var panel = $("#MGoodsPanel");
	var html = "";
	for(var i = 0; i < result.length; i++) {
		var v = result[i];
		if(typeof(goods[v.id]) == "undefined" || goods[v.id] == null) {
			goods[v.id] = v.sn;
			html += '    <tbody><tr>'
				+ '      <td>' + v.sn + '<input type="hidden" name="wprice_' + v.id + '" id="wprice_' + v.id + '" value="' + v.wprice + '"  />'
				
				+ '      <input name="discount_' + v.id + '" type="hidden" id="discount_' + v.id + '" value="100" size="10"  />'
				+ '      <input name="sprice_' + v.id + '" type="hidden" id="sprice_' + v.id + '" size="10">'
				+ '      <input name="sumMoney_' + v.id + '" type="hidden" id="sumMoney_' + v.id + '" size="10">'
				
				+ '</td>'
				+ '      <td>' + v.name + '</td>'
				+ '      <td><input name="amount_' + v.id + '" type="text" id="amount_' + v.id + '" value="0" size="10"  onChange="calcGoodsTotalM(this,' + v.id + ',' + v.wprice + ')" /></td>';
				
				html += '      <td>' + v.weight + '</td>'
				+ '      <td>' + v.unit + '</td>'
				+ '      <td><a href="#" onClick="deleteGoods(this, ' + v.id + ')">删除</a></td>'
				+ '    </tr>';
		}
	}
	html = html+'</tbody>';
	panel.append(html);
}
function deleteGoods(el, id) {
	var row = $(el).parent().parent();
	row.remove();
	goods[id] = null;
	delete goods[id];
}
function calcGoodsTotalM(el, id) {	
	var obj = $(el);
	var prefix = obj.attr("name").split('_')[0];
	var sprice = $("#sprice_"+id).val();
	var discount = $("#discount_"+id).val();
	var sumMoney = $("#sumMoney_"+id).val();
	var wprice = $("#wprice_"+id).val();
	var amount = $("#amount_"+id).val();
	if(prefix == "discount" || prefix == "amount") {
		$("#sprice_"+id).attr("value", discount * wprice / 100);
		$("#sumMoney_"+id).attr("value",(discount * wprice / 100 * amount).toFixedU(2));
	} else if(prefix == "sprice") {
		$("#discount_"+id).attr("value", parseInt(sprice / wprice * 100));
		$("#sumMoney_"+id).attr("value", (sprice * amount).toFixedU(2));
	} else {
		$("#discount_"+id).attr("value", parseInt((sumMoney / amount).toFixedU(2) / wprice * 100));
		$("#sprice_"+id).attr("value", (sumMoney / amount).toFixedU(2));
	}
	
}
	</script>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" class="listLogo">
	<tr>
		<td class="title">生产计划单修改</td>
		<td>
			<div class="menuTool">
				<a class="save" id="dataFormSave" href="#">保存</a>
				<a class="back" href="getSellPlanApp.htm">返回</a>
			</div>
		</td>
	</tr>
</table>
<div class="line"></div>
<form id="dataForm" method="post" action="updSellPlanApp${action+1}.htm">
<input type="hidden" name="goodsInfo" id="goodsInfo" value="" />
<table border="0" cellspacing="1" cellpadding="0" class="listTable">
	<tr>
		<td class="form_title">计划单号：</td>
		<td class="form_input"><input type="hidden" id="app_code" name="app_code" value="${fn:escapeXml(po.app_code)}" />
		  ${po.app_code}</td>
	</tr>
    <c:choose>
				<c:when test="${action == 1}">
	<tr>
		<td class="form_title">计划性质：</td>
		<td class="form_input"><select name="app_type" id="app_type">
		  <option value="1"<c:if test="${po.app_type == 0}"> selected</c:if>>销售</option>
          <option value="2"<c:if test="${po.app_type == 0}"> selected</c:if>>库存</option>
          <option value="3"<c:if test="${po.app_type == 0}"> selected</c:if>>固定</option>
          <option value="4"<c:if test="${po.app_type == 0}"> selected</c:if>>临时</option>
	    </select></td>
	</tr>
    <tr>
		<td class="form_title">客户代码：</td>
		<td class="form_input"><input type="text" id="custom_code" name="custom_code" value="${po.custom_code}" /></td>
	</tr>
	<tr>
		<td class="form_title">制单日期：</td>
		<td class="form_input"><input type="text" id="create_date" name="create_date" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${po.create_date}" />" readonly="readonly" class="Wdate" onFocus="WdatePicker({isShowWeek:true})" /></td>
	</tr>
    </c:when>
    <c:when test="${action == 3}">
	<tr>
		<td class="form_title">提交日期：</td>
		<td class="form_input"><input type="text" id="submit_date" name="submit_date" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${po.submit_date}" />" readonly="readonly" class="Wdate" onFocus="WdatePicker({isShowWeek:true})" /></td>
	</tr>
	<tr>
		<td class="form_title">备注：</td>
		<td class="form_input"><textarea name="remark" cols="50" rows="5" id="remark">${fn:escapeXml(po.remark)}</textarea></td>
	</tr>
    </c:when>
    <c:otherwise>
	<tr>
		<td class="form_title">安排生产日期：</td>
		<td class="form_input"><input type="text" id="pro_date" name="pro_date" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${po.pro_date}" />" readonly="readonly" class="Wdate" onFocus="WdatePicker({isShowWeek:true})" /></td>
	</tr>
    <tr>
		<td class="form_title">安排生产备注：</td>
		<td class="form_input"><textarea name="pro_remark" cols="50" rows="5" id="pro_remark">${fn:escapeXml(po.pro_remark)}</textarea></td>
	</tr>
	<tr>
		<td class="form_title">生产完成日期：</td>
		<td class="form_input"><input type="text" id="com_date" name="com_date" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${po.com_date}" />" readonly="readonly" class="Wdate" onFocus="WdatePicker({isShowWeek:true})" /></td>
	</tr>
    <tr>
	  <td class="form_title">生产完成备注：</td>
		<td class="form_input"><textarea name="com_remark" cols="50" rows="5" id="com_remark">${fn:escapeXml(po.com_remark)}</textarea></td>
	</tr>
    </c:otherwise>
    </c:choose>
	
    <tr>
	  <td class="form_title">产品报价</td>
	  <td class="form_input"><table width="340" border="0"
						cellpadding="2" cellspacing="1" class="listLogo" id="MGoodsPanel">
						<tr>
							<td>产品代码</td>
							<td>产品名称</td>
							<td>订购数量</td>
							<td>重量</td>
							<td>计量单位</td>
                            <c:if test="${action == 1}">
								<td><input type="button" name="button" id="button"
									value="增加产品" onClick="selectGoods()">
								</td>
                                </c:if>
						</tr>
						<c:forEach items="${refGoods}" var="rg" varStatus="status">
							<tr>
							  <td><script>goods[${rg.goods_id}] = '${rg.goods_sn}';</script>${rg.goods_sn}<input
									type="hidden" name="ref_id" value="${rg.id}" /> <input
									type="hidden" name="wprice_${rg.goods_id}"
									id="wprice_${rg.goods_id}" value="${rg.wprice}" />
							    <input name="discount_${rg.goods_id}" type="hidden"
												id="discount_${rg.goods_id}"
												onChange="calcGoodsTotalM(this,${rg.goods_id})"
												value="${rg.discount}" size="10" />
							    <input name="sprice_${rg.goods_id}" type="hidden"
												id="sprice_${rg.goods_id}" size="10" value="${rg.sprice}" onChange="calcGoodsTotalM(this,${rg.goods_id})">
							    <input name="sumMoney_${rg.goods_id}" type="hidden"
												id="sumMoney_${rg.goods_id}" size="10"
												value="${rg.sumMoney}" onChange="calcGoodsTotalM(this,${rg.goods_id})"></td>
								<td>${rg.goods_name} </td>
								<td>
                                <c:choose>
								<c:when test="${action == 1}">
											<input name="amount_${rg.goods_id}" type="text"
												id="amount_${rg.goods_id}" value="${rg.amount}" size="10" />
                                </c:when>
                                <c:otherwise>
                                               ${rg.amount}
                                </c:otherwise>
                                </c:choose>
							  </td>
								<td>${rg.weight} </td>
								<td>${rg.unit} </td>
                                    <c:if test="${action == 1}">
									<td><a href="#"
										onClick="deleteGoods(this, ${rg.goods_id})">删除</a></td>
                                    </c:if>
							</tr>
						</c:forEach>
					</table></td>
    </tr>
</table>
<input type="hidden" name="id" value="${po.id}" />
</form>
</body>
</html>
